define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pdd/goods/index' + location.search,
                    add_url: 'pdd/goods/add',
                    edit_url: 'pdd/goods/edit',
                    del_url: 'pdd/goods/del',
                    multi_url: 'pdd/goods/multi',
                    import_url: 'pdd/goods/import',
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'goods_id', title: __('Goods_id'),operate: 'IN'},
                        {field: 'origin', title: __('Origin'), operate: 'LIKE'},
                        {
                            field: 'data', title: __('Data'),operate: 'LIKE', cellStyle: Controller.api.formatter.formatTableUnit,
                            formatter: Controller.api.formatter.paramsMatter
                        },
                        {
                            field: 'hasGoodsProperty',
                            title: __('Hasgoodsproperty'),
                            formatter: Table.api.formatter.status,
                            searchList: {1: __('是'), 0: __('否')}
                        },
                        {
                            field: 'getTime',
                            title: __('Gettime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                formatTableUnit: function (value, row, index) {
                    return {
                        css: {
                            "white-space": "nowrap",
                            "text-overflow": "ellipsis",
                            "overflow": "hidden",
                            "max-width": "300px",
                            "cursor": "pointer"
                        }
                    }
                },
                paramsMatter: function (value, row, index, field) {
                    var span = document.createElement('span');
                    span.setAttribute('title', value);
                    span.innerHTML = value;
                    return span.outerHTML;
                }
            }
        }
    };
    return Controller;
});
